package com.algorithm;

/**
 * 移动零
 */
public class MoveZeroes {

    public static void moveZeroes(int[] nums) {
        for (int i = 0, j=0; i < nums.length&&j<nums.length; i++) {
            if (nums[i]!=0){
                nums[j]=nums[i];
                j++;
            }
            if (i==nums.length-1){
                for (;j<nums.length;j++){
                    nums[j]=0;
                }
            }
        }
    }

    public static void main(String[] args) {
        int [] nums={0,1,0,3,12};
        moveZeroes(nums);
        System.out.println(nums);
    }
}
